package com.ssm.dao.daoTest;

import com.ssm.dao.IUserDao;
import com.ssm.model.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.ArrayList;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"classpath:spring-mybatis.xml"})
public class UserDaoTest {
    @Autowired
    private IUserDao dao;

    @Test
    public void testSelectUser() throws Exception {
        int userId = 1;
        User user = dao.selectDao(userId);
        System.out.println(user);
    }

    @Test
    public void  testSelectAll() throws Exception{
        ArrayList<User> list = dao.selectAll();
        for(int i = 0; i<list.size(); i++){
            System.out.println(list.get(i));
        }
    }

    @Test
    public void  testDelUser() throws Exception{
        int userId = 3;
        Boolean b = dao.delDao(userId);
        System.out.println(b);
        ArrayList<User> list = dao.selectAll();
        for(int i = 0; i<list.size(); i++){
            System.out.println(list.get(i));
        }
    }

    @Test
    public void  testAddUser() throws Exception{
        User user = new User();
        user.setId(4);
        user.setName("赵小四");
        user.setSex("女");
        Boolean b = dao.addDao(user);
        System.out.println(b);
        ArrayList<User> list = dao.selectAll();
        for(int i = 0; i<list.size(); i++){
            System.out.println(list.get(i));
        }
    }

    @Test
    public void  testUpdateUser() throws Exception{
        User user = new User();
        user.setId(4);
        user.setName("赵小四");
        user.setSex("男");
        Boolean b = dao.updateDao(user);
        System.out.println(b);
        ArrayList<User> list = dao.selectAll();
        for(int i = 0; i<list.size(); i++){
            System.out.println(list.get(i));
        }
    }
}
